<?php

class User_model extends CI_Model
{
	
	public function __construct()
	{
		$this->load->database();
		$this->load->library('session');
	}
	public function getRight($data)
	{
		$flag = false;
		$sql = 'SELECT auto_id FROM '.CI_Model::$user.' WHERE user_id = ? ;';
		$result = $this->db->query($sql,array($data['user']))->row_array();
		
		$flag  = ($data['pass'] == $_SESSION['password']);
		//return $flag;
		return isset($result['auto_id'])&&$flag ? true : false;
	}
	public function getID($data)
	{
		$sql = 'SELECT auto_id FROM '.CI_Model::$user.' WHERE user_id = ? ;';
		return $this->db->query($sql,array($data['user']))->row_array()['auto_id'];
	}
	public function getInfo($user_id)
	{
		$sql = 'SELECT * FROM '.CI_Model::$userInfo.' WHERE user_id = ? ;';
		$result = $this->db->query($sql,array($user_id))->row_array();
		return isset($result['user_id'])? $result : null;
	}
	public function addUser($user_id)
	{
		$sql = 'INSERT INTO '.CI_Model::$user.' (auto_id,user_id,create_time) VALUES (null,?,?);';
		return $this->db->query($sql,array($user_id,date('Y-m-d H:i:s')))->result();
	}
	public function selectLastModified($user_id)
	{
		$sql = 'SELECT table_name,update_time FROM record WHERE owner_id = ? ORDER BY update_time DESC, create_time desc LIMIT 1;';
		$result = $this->db->query($sql,array($user_id))->row_array();
		return isset($result['table_name'])?$result['table_name']: null;
	}
}